//
//  ViewController.m
//  3.17hit
//
//  Created by student on 16/3/17.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"
#import "MyButton.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIButton *btn;


@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // 5. 拖动手势 (和轻扫的区别:得到距离)
    UIPanGestureRecognizer *panR = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveV:)];
    [self.btn addGestureRecognizer:panR];

}

- (void)moveV:(UIPanGestureRecognizer *)g
{
    // 偏移多少
    CGPoint tran = [g translationInView:self.btn];

    // 加上偏移
    self.btn.center = CGPointMake(self.btn.center.x+tran.x, self.btn.center.y+tran.y);

    // 重置偏移量
    [g setTranslation:CGPointZero inView:self.btn];

}
- (IBAction)btnPressed:(MyButton *)sender {
    if(sender.addBtn != nil)
    {
        [sender.addBtn removeFromSuperview];
    }
    
    else
    {
        NSLog(@"%@",NSStringFromCGRect(sender.bounds));
        
        //    sender.clipsToBounds = YES;// 超出bounds范围的子视图不显示
        
        UIButton *btn = [[UIButton alloc] init];
        
        // 大小
        btn.bounds = CGRectMake(0, 0, 200, 200);
        // 中心点
        btn.center = CGPointMake(100, -100);
        
        [btn setBackgroundImage:[UIImage imageNamed:@"对话框.png"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"小孩.png"] forState:UIControlStateHighlighted];
        
        [sender addSubview:btn];
        
        sender.addBtn = btn;
    }

}

@end
